#include "Util.h"
#include <shlwapi.h>
#include <wchar.h>

namespace util{
    Wstr_struct::Wstr_struct(const wchar_t * wstr){
        if(wstr == nullptr){
            storage = nullptr;
            return;
        }
        int len = 0;
        for(;wstr[len] != 0; len++) {}
        storage = new wchar_t[len];
        wcscpy(const_cast<wchar_t *>(storage), wstr);
    }

    Wstr_struct::Wstr_struct(const char * str){
        if(str == nullptr){
            storage = nullptr;
            return;
        }
        int len = 0;
        for(;str[len] != 0; len++) {}
        storage = new wchar_t[len];
        mbstate_t ps;
        mbsrtowcs(const_cast<wchar_t *>(storage), &str, len, &ps);
    }

    const wchar_t * Wstr_struct::get(){
        return storage;
    }

    Wstr_struct::~Wstr_struct(){
        if(storage != nullptr)
            delete[] storage;
    }
}